#include "SearchedCardsDialog.h"

#include <boost/bind.hpp>

using namespace Views::Helpers::Graphic;
using namespace Views::Helpers::Graphic::Deduction;
using namespace Utils;

SearchedCardsDialog::SearchedCardsDialog(Cards::PlayersCards players_cards, Cards::WeaponsCards weapons_cards)
	:picked_player(NULL), picked_weapon(NULL)
{
	players_cards_group = new PlayersCardsGroup(players_cards, true);
	weapons_cards_group = new WeaponsCardsGroup(weapons_cards, true);

	players_cards_group->doOnCardPick(boost::bind(&SearchedCardsDialog::onPlayerCardClick, this, _1));
	weapons_cards_group->doOnCardPick(boost::bind(&SearchedCardsDialog::onWeaponCardClick, this, _1));

	players_cards_group->Move(10, 10);
	weapons_cards_group->Move(10 + players_cards_group->GetWidth() + 10, 10);

	addChild(players_cards_group);
	addChild(weapons_cards_group);

	int height = players_cards_group->GetHeight() > weapons_cards_group->GetHeight() ?
		players_cards_group->GetHeight(): weapons_cards_group->GetHeight();

	Shape = sf::Shape::Rectangle(0, 0, 10 + players_cards_group->GetWidthF() + 10 + players_cards_group->GetWidthF() + 10,
		static_cast<float>(10 + height + 10), sf::Color(255, 50, 50));
};

void SearchedCardsDialog::onPlayerCardClick(Cards::PlayerCard* player)
{
	picked_player = player;
	if (picked_player != NULL && picked_weapon != NULL)
	{
		cardsPickEvent(picked_player, picked_weapon);
	}
}

void SearchedCardsDialog::onWeaponCardClick(Cards::WeaponCard* weapon)
{
	picked_weapon = weapon;
	if (picked_player != NULL && picked_weapon != NULL)
	{
		cardsPickEvent(picked_player, picked_weapon);
	}
}

boost::signals::connection SearchedCardsDialog::doOnCardsPick(const OnCardsPick::slot_function_type& slot)
{
	return cardsPickEvent.connect(slot);
}

